@page "/PersistentVolume"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using k8s.Models
@inherits BlazorApp.Pages.Common.TableBase<V1PersistentVolume>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd >
                <SearchToolBar Title=@L["PersistentVolume"] Count="@TableData.Total"
                               OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection"
                               TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1PersistentVolume"
                               OnNsSelected="OnNsSelectedHandler"
                               HideNsSelector="true">
                </SearchToolBar>
            </HTd>
        </HTr>
        <HTr>
            <HTd >
                <Table TItem="V1PersistentVolume"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title=@L["Name"]>
                        <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Capacity"] TData="string">
                        @foreach (var (key, value) in context.Spec.Capacity)
                        {
                            <div>
                                <ColorfulTag>@($"{key}={value}")</ColorfulTag>
                            </div>
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["AccessModes"] TData="string">
                        @foreach (var mode in context.Spec.AccessModes)
                        {
                            <div>
                                <ColorfulTag>@mode</ColorfulTag>
                            </div>
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["ReclaimPolicy"] TData="string">
                        <ColorfulTag>@context.Spec.PersistentVolumeReclaimPolicy</ColorfulTag>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Status"] TData="string">
                        <ColorfulTag>@context.Status.Phase</ColorfulTag>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Claim"] TData="string">
                        <RefView Ref="@context.Spec.ClaimRef"></RefView>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["StorageClass"] TData="string">
                        <ColorfulTag>@context.Spec.StorageClassName</ColorfulTag>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["VolumeMode"] TData="string">
                        <ColorfulTag>@context.Spec.VolumeMode</ColorfulTag>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Age"] TData="string" Width="100px">
                        <AgeView Age="@context.CreationTimestamp()"></AgeView>
                    </AntDesign.Column>
                    <ActionColumn Title=@L["Action"] Width="100px">
                        <PersistentVolumeAction Item="@context"></PersistentVolumeAction>
                    </ActionColumn>
                </Table>
            </HTd>
        </HTr>
    </HTable>
    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1PersistentVolume"></ResourceWatcher>
}
